package com.itcam.list_.collection_;

import com.itcam.list_.collection_.domain.Student;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Author:Cammy.Wu
 * Date:2024-05-14
 * Description:共有的方法
 */

public class CollectionDemo01 {
    /**
     * Collection的常用方法：
     * <p>
     * public boolean add(E e):把给定的对象添加到当前集合中
     * public void clear():清空集合中所有的元素
     * public boolean remove(E e):把给定的对象在当前集合中删除
     * public boolean conntains(Object obj):判断当前集合中是否包含给定的对象
     * public boolean isEmpty():判断当前集合是否为空
     * public int size():返回集合中元素的个数（集合的长度）
     */

    public static void main(String[] args) {
        Collection<Student> c = new ArrayList<>();

        c.add(new Student("Cammy", 88));
        c.add(new Student("Jerry", 18));
        c.add(new Student("Tim", 55));

        System.out.println("c = " + c);

        c.remove(new Student("Tim", 55));
        System.out.println("c = " + c);

        System.out.println(c.contains(new Student("Cammy", 88)));

    }

    private static void method() {
        // 以多态的形式创建集合对象，调用单列集合的共有方法
        Collection<String> c = new ArrayList<>();
//        Collection<String> c = new HashSet<>();

        boolean b1 = c.add("cammy");
        boolean b2 = c.add("jerry");
        boolean b3 = c.add("tom");

        System.out.println(b1);
        System.out.println(b2);
        System.out.println(b3);

        System.out.println("c = " + c);

//        c.clear();
//        System.out.println("c = " + c);
//
//        c=null;
//        System.out.println(c.isEmpty());

        boolean is = c.remove("tom");
        System.out.println("is = " + is);
        System.out.println("c = " + c);

        is = c.contains("cammy");
        System.out.println("is = " + is);
        System.out.println("c = " + c);

        System.out.println(c.size());
    }
}
